<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>学生成绩管理系统</title>
	</head>
	<body>
	</body>
	<script>
		const CAS = 'http://localhost:8080';
		const BACKEND = 'http://localhost:8082';
		const PARAMS = new URLSearchParams(window.location.search);
		const TOKEN = PARAMS.get("token");
		if (TOKEN === null || TOKEN === undefined || TOKEN.trim() === '') {  
		    window.location.href = `${CAS}/login-page?return-address=${encodeURIComponent(window.location.href)}`;
		} else {
			const apiUrl = `${BACKEND}/user/info?token=${TOKEN}`;
			fetch(apiUrl, {
				credentials: "include"
			})
				.then(response => {  
					if (!response.ok) {  
						window.location.reload();
					}  
					return response.json();  
				})  
				.then(data => {
					const account = data.account;
					localStorage.setItem('account', account);
					if (account.startsWith('a')) {
						window.location.href = './admin/student/index.html';
					} else if (account.startsWith('t')) {
						window.location.href = './teacher/index.html';
					} else {
						window.location.href = './student/index.html';
					}
				})
				.catch(error => {  
					console.error('Error fetching classes:', error);  
				});
		}
	</script>
</html>